import { Catch } from '@midwayjs/decorator'
import { Context } from '@midwayjs/koa'
import { MidwayValidationError } from '@midwayjs/validate'


@Catch(MidwayValidationError)
export class ValidateErrorFilter {
  async catch(err: MidwayValidationError, ctx: Context) {
    ctx.status = 422;
    ctx.logger.error(err);
    return {
      code: 422,
      message: err.message,
    }
  }
}
